package cn.wolfcode.wolf2w.common.redis.util;

import lombok.Getter;

import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;

@Getter
/*使用枚举创建一个redis工具类，用于拼接前缀和设置过期时间*/
public enum RedisKeys {
    USER_NOTE_THUMBSUP("user_note_thumbsup", -1L),
    USER_NOTE_COLLECT("user_note_collect", -1L),
    NOTE_STATIS_HASH("note_statis_hash", -1L),
    USER_STRATEGY_THUMBSUP("user_strategy_thumbsup", -2L),
    USER_STRATEGY_FAVOR("user_strategy_favor", -1L),

    STRATGE_STATIS_HASH("strategy_statis_hash", -1L),


    VERIFY_CODE("verify_code", 5 * 60);

    private String prefix;//key 前缀
    private long time;//key 过期时间

    private RedisKeys(String prefix, long time) {
        this.prefix = prefix;
        this.time = time;
    }

    public String join(String... value) {
        StringBuffer sb = new StringBuffer();
        sb.append(this.prefix);
        for (String v : value) {
            sb.append(":").append(v);
        }
        return sb.toString();
    }

    public static long getNextDayTime() {
        //获取第二天零点
        LocalDateTime localDateTime = LocalDateTime.now().with(LocalTime.MAX).plusNanos(1);

        //获取当前时间
        LocalDateTime now = LocalDateTime.now();
        //获取时间差
        long until = now.until(localDateTime, ChronoUnit.SECONDS);
        return until;

    }


}
